/*
 * @Description:获取字段唯一值列表
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2022-12-17 11:25:50
 * @LastEditors: wiz
 * @LastEditTime: 2024-03-10 09:16:30
 */
import lexicon from '@/lib/lexicon';
import { I_sort } from './base/sort';
import { T_stdReq } from './base/stdReq';

export class T_GPFD extends T_stdReq {
  private url: string = lexicon.url.getFilterList;

  // 全局搜索 以空隔隔开
  protected globalSearch: string;

  protected filter: object;

  protected sort: I_sort[];

  protected options: {
    // 值重复去重，支持多字段
    isDistinct: boolean;

    // 是否分页
    isPagingQuery: boolean;

    // 指定返回字段，如果字段带slc,m20返连虚拟字段一起返回
    agreedFields: Array<string>;

    // 排除的返回字段内容优先级高于AgreedFields
    excludedFields?: Array<string>;

    // 统计作用  ————  指定数据的统计数据
    isCount?: boolean;

    // 分页配置
    pageNo?: number;

    // 分页配置
    pageSize?: number;
  };

  constructor() {
    super();
    this.sort = [] as I_sort[];
    this.filter = {};
    this.options = {
      isDistinct: false,
      isPagingQuery: false,
      agreedFields: []
    };
    this.globalSearch = '';
  }

  // 求唯一值
  setIsDistinct(p: boolean): T_GPFD {
    this.options.isDistinct = p;
    return this;
  }

  // 是否需要分页
  setIsPagingQuery(p: boolean): T_GPFD {
    this.options.isPagingQuery = p;
    return this;
  }

  /**
   * 设置页码
   * @param pageNo
   * @param pageSize
   */
  setPage(pageNo: number, pageSize: number): T_GPFD {
    this.options.pageSize = pageSize;
    this.options.pageNo = pageNo;
    return this;
  }

  // 指定返回字段，如果字段带slc,m20返连虚拟字段一起返回
  setAgreedFields(...p: string[]): T_GPFD {
    this.options.agreedFields.push(...p);
    return this;
  }

  setGlobalSerach(p: string): T_GPFD {
    this.globalSearch = p;
    return this;
  }

  setFilter(p: object): T_GPFD {
    this.filter = p;
    return this;
  }

  setSort(p: I_sort[]): T_GPFD {
    this.sort = p;
    return this;
  }
}
export interface I_GPFD extends T_GPFD {}
